package com.member.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.member.common.annotation.Excel;
import com.member.common.utils.DateUtils;
import com.member.shop.domain.SysBizMarketPageCategory;
import com.member.shop.mapper.SysBizMarketPageCategoryMapper;
import com.member.shop.service.ISysBizMarketPageCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 营销页面分类定义Service业务层处理
 *
 * @author lixinchen
 * @date 2025-02-14
 */
@Service
public class SysBizMarketPageCategoryServiceImpl extends ServiceImpl<SysBizMarketPageCategoryMapper, SysBizMarketPageCategory> implements ISysBizMarketPageCategoryService {
    @Resource
    private SysBizMarketPageCategoryMapper sysBizMarketPageCategoryMapper;

    /**
     * 查询营销页面分类定义
     *
     * @param id 营销页面分类定义主键
     * @return 营销页面分类定义
     */
    @Override
    public SysBizMarketPageCategory selectSysBizMarketPageCategoryById(Long id) {
        return sysBizMarketPageCategoryMapper.selectById(id);
    }

    /**
     * 查询营销页面分类定义列表
     *
     * @param queryWrapper 营销页面分类定义
     * @return 营销页面分类定义
     */
    @Override
    public List<SysBizMarketPageCategory> selectSysBizMarketPageCategoryList(LambdaQueryWrapper<SysBizMarketPageCategory> queryWrapper) {
        return sysBizMarketPageCategoryMapper.selectList(queryWrapper);
    }

    /**
     * 查询营销页面分类定义列表
     *
     * @param sysBizMarketPageCategory 营销页面分类定义
     * @return 营销页面分类定义
     */
    @Override
    public List<SysBizMarketPageCategory> selectSysBizMarketPageCategoryList(SysBizMarketPageCategory sysBizMarketPageCategory) {
        return sysBizMarketPageCategoryMapper.selectSysBizMarketPageCategoryList(sysBizMarketPageCategory);
    }

    /**
     * 新增营销页面分类定义
     *
     * @param sysBizMarketPageCategory 营销页面分类定义
     * @return 结果
     */
    @Override
    public int insertSysBizMarketPageCategory(SysBizMarketPageCategory sysBizMarketPageCategory) {
        sysBizMarketPageCategory.setCreateTime(DateUtils.getNowDate());
        bussTypeChange(sysBizMarketPageCategory);
        return sysBizMarketPageCategoryMapper.insert(sysBizMarketPageCategory);
    }

    /**
     * 修改营销页面分类定义
     *
     * @param sysBizMarketPageCategory 营销页面分类定义
     * @return 结果
     */
    @Override
    public int updateSysBizMarketPageCategory(SysBizMarketPageCategory sysBizMarketPageCategory) {
        sysBizMarketPageCategory.setUpdateTime(DateUtils.getNowDate());
        bussTypeChange(sysBizMarketPageCategory);
        return sysBizMarketPageCategoryMapper.updateById(sysBizMarketPageCategory);
    }
    private void bussTypeChange(SysBizMarketPageCategory sysBizMarketPageCategory) {
        //优惠券
        if (sysBizMarketPageCategory.getBussType() == 0) {
            sysBizMarketPageCategory.setBgTopImg(null);
            sysBizMarketPageCategory.setCategoryBgType(null);
            sysBizMarketPageCategory.setCategoryBgPic(null);
            sysBizMarketPageCategory.setGoodsStructure(null);
            sysBizMarketPageCategory.setGoodsLayout(null);
            sysBizMarketPageCategory.setCarouselType(null);
            sysBizMarketPageCategory.setActivityStartTime(null);
            sysBizMarketPageCategory.setActivityEndTime(null);
            sysBizMarketPageCategory.setLongitude(null);
            sysBizMarketPageCategory.setLatitude(null);
            sysBizMarketPageCategory.setActivityType(null);
            sysBizMarketPageCategory.setGoodsId(null);
        } else if (sysBizMarketPageCategory.getBussType() == 1) {
            sysBizMarketPageCategory.setCouponImgFront(null);
            sysBizMarketPageCategory.setCouponImgAfter(null);
            sysBizMarketPageCategory.setCouponPageType(null);
            sysBizMarketPageCategory.setCouponId(null);
        }
    }

    /**
     * 批量删除营销页面分类定义
     *
     * @param ids 需要删除的营销页面分类定义主键
     * @return 结果
     */
    @Override
    public int deleteSysBizMarketPageCategoryByIds(Long[] ids) {
        return sysBizMarketPageCategoryMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除营销页面分类定义信息
     *
     * @param id 营销页面分类定义主键
     * @return 结果
     */
    @Override
    public int deleteSysBizMarketPageCategoryById(Long id) {
        SysBizMarketPageCategory sysBizMarketPageCategory = new SysBizMarketPageCategory();
        sysBizMarketPageCategory.setId(id);
        sysBizMarketPageCategory.setDeleted(1);
        return sysBizMarketPageCategoryMapper.updateById(sysBizMarketPageCategory);
    }
}
